package pl.taskman.view;

import java.awt.Color;

import info.clearthought.layout.TableLayout;

import javax.swing.*;

import pl.taskman.view.components.CustomButton;
import pl.taskman.view.components.CustomPanel;
import pl.taskman.view.components.CustomPasswordField;

public class LoginViewPanel extends CustomPanel
{
	/**
	 * Generated serial ID
	 */
	private static final long	serialVersionUID	= -4666607504385367274L;

	private CustomButton		button_login		= null;
	private CustomButton		button_cancel		= null;
	// private CustomButton button_addUser = null;
	// private CustomButton button_removeUser = null;
	private JCheckBox			cb					= null;
	private JComboBox			usersDropList		= null;
	private CustomPasswordField	pwField				= null;
	private JLabel				label_login			= null;
	private JLabel				label_password		= null;
	private Color				color				= null;

	// TO_BE_REMOVED ##############################
	private String[]			users				= { "NiTh", "m4rt" };

	// ############################################

	public LoginViewPanel(Color color)
	{
		super(color);
		this.color = color;
		initComponents();
		localInitialization();
	}

	private void localInitialization()
	{
		// TODO Auto-generated method stub

	}

	private void initComponents()
	{
		button_cancel = new CustomButton(color);
		button_login = new CustomButton(color);
		// button_addUser = new CustomButton();
		// button_removeUser = new CustomButton();
		cb = new JCheckBox();
		usersDropList = new JComboBox();
		pwField = new CustomPasswordField(color);
		label_login = new JLabel("Login:");
		label_password = new JLabel("Password:");

		// initializing exit button
		{
			button_cancel.setText("Exit");
			// button_cancel.addActionListener(Manager.getActionListener());
			button_cancel.setActionCommand("QUIT");
		}

		// initializing login button
		{
			button_login.setText("Log in");
			// button_login.addActionListener(Manager.getActionListener());
			button_login.setActionCommand("LOG_IN");
		}

		// initializing add-user button
		{
			// button_addUser.setText("+");
			// // button_addUser.addActionListener(Manager.getActionListener());
			// button_addUser.setActionCommand("ADD_USER");
		}

		// initializing remove-user button
		{
			// button_removeUser.setText("-");
			// //
			// button_removeUser.addActionListener(Manager.getActionListener());
			// button_removeUser.setActionCommand("REMOVE_USER");
		}

		// initializing 'remember me' checkbox
		{
			// cb.addActionListener(Manager.getActionListener());
			cb.setActionCommand("REMEMBER_ME");
		}

		// initializing users dropdown list
		{
			// TODO: integrate with rego's integration controller
			for (int i = 0; i < users.length; i++)
				usersDropList.addItem(users[i]);
			// usersDropList.addActionListener(Manager.getActionListener());
		}

		// Set font color
		{
			label_login.setForeground(Color.WHITE);
			label_password.setForeground(Color.WHITE);
		}

		{
			// double size[][] = {
			// { 0.1, 0.2, 0.05, 0.2, 0.05, 0.05, 0.2, 0.05, 0.1 },
			// { TableLayout.FILL, 0.1, 0.05, 0.1, 0.1, 0.1,
			// TableLayout.FILL } };
			// setLayout(new TableLayout(size));
			// add(label_login, "1,1");
			// add(button_addUser, "2,1");
			// add(usersDropList, "3,1 , 6,1");
			// add(button_removeUser, "7,1");
			//
			// add(label_password, "1,3");
			// add(pwField, "2,3 , 7,3");
			//
			// add(button_login, "3,5");
			// add(button_cancel, "6,5");
		}

		{
			double size[][] = { { 0.1, 0.2, 0.1, 0.2, 0.1, 0.2, 0.1 },
					{ 0.2, 0.1, 0.1, 0.1, 0.15, 0.15, 0.2 } };

			setLayout(new TableLayout(size));

			add(label_login, "1, 1");
			add(usersDropList, "3, 1, 5, 1");

			add(label_password, "1, 3");
			add(pwField, "3, 3, 5, 3");

			add(button_login, "3, 5");
			add(button_cancel, "5, 5");
		}
	}
}
